import './assets/main.css'
import './styles/element/index.scss'

import {createApp, ref} from 'vue'
import {createRouter, createWebHashHistory} from 'vue-router'
import ElementPlus from 'element-plus'
import App from './App.vue'

import Policy from './assets/pages/Policy/Policy.vue'
import Shop from "@/assets/pages/Shop/Shop.vue";
import Index from "./assets/pages/Index/Index.vue";
import Consult from "./assets/pages/Consult/Consult.vue";
import Manage from "./assets/pages/Manage/Manage.vue";
import PolicyDetail from "./assets/pages/Policy/PolicyDetail.vue";
import GoodsDetail from "./assets/pages/Shop/GoodsDetail.vue";
import axios from "axios";
import MyOrder from "./assets/pages/MyOrder/MyOrder.vue";
import SellerCenter from "./assets/pages/SellerCenter/SellerCenter.vue";
import MyAccount from "./assets/pages/MyAccount/MyAccount.vue";
import Agritainment from "./assets/pages/Agritainment/Agritainment.vue";
import AgritainmentDetail from "./assets/pages/Agritainment/AgritainmentDetail.vue";

// todo
// export const ServerHost = "http://localhost:9904/api"
export const ServerHost = "http://shiyue0x0.top:9904/api"
const titleAppend = " - 乡兴助农"

export const loginUser = ref({})
loginUser.value = JSON.parse(localStorage.getItem('loginUser'))

export const updateUserInfo = () => {
    if (!loginUser.value) {
        return
    }
    axios.get(`${ServerHost}/getUser?id=${loginUser.value.id}`)
        .then((res) => {
            if (res.status === 200) {
                loginUser.value = res.data
                localStorage.setItem('loginUser', JSON.stringify(res.data))
                console.log(loginUser.value)
            }
        })
}
updateUserInfo()

export const orderStatusEnum = {
    "待发货": 0,
    "待收货": 1,
    "已完成": 2,
}



export const paymentEnum = {
    "wechatPayment": "微信支付",
    "alipay": "支付宝",
    "card": "银行卡",
}

const routes = [{
    path: '/', component: Index, meta: {
        title: `乡兴助农`
    }
}, {
    path: '/Policy', component: Policy, meta: {
        title: `扶贫政策${titleAppend}`
    }
}, {
    path: '/consult', component: Consult, meta: {
        title: `助农咨询${titleAppend}`
    }
}, {
    path: '/manage', component: Manage, meta: {
        title: `管理${titleAppend}`
    }
}, {
    path: '/shop', component: Shop, meta: {
        title: `农产品${titleAppend}`
    }
}, {
    path: '/my-order', component: MyOrder, meta: {
        title: `我的订单${titleAppend}`
    }
}, {
    path: '/seller-center', component: SellerCenter, meta: {
        title: `商家中心${titleAppend}`
    }
}, {
    path: '/my-account', component: MyAccount, meta: {
        title: `我的账号${titleAppend}`
    }
},{
    path: '/agritainment', component: Agritainment, meta: {
        title: `农家乐${titleAppend}`
    }
},
    {
        path: '/Policy/:id', component: PolicyDetail
    }, {
        path: '/goods/:id', component: GoodsDetail
    }, {
        path: '/agritainment/:id', component: AgritainmentDetail
    }
]
const router = createRouter({
    mode: 'hash',
    history: createWebHashHistory(),
    routes: routes
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title as string
    }
    next()
})

createApp(App)
    .use(router)
    .use(ElementPlus)
    .mount('#app')
